package com.moyu.shopapp.controller;

import com.moyu.shopapp.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/alipay")
public class AlipayController {
    /**
     * web端订单支付
     *
     * @param outTradeNo 订单编号（唯一）
     * @param totalAmount 订单价格
     * @param subject 商品名称
     */
    @Autowired
    AlipayService alipayService;

    @PostMapping("/pay")
    public String webPagePay(String outTradeNo, String subject, String totalAmount) {
        System.out.println("pay");
        return alipayService.webPagePay(subject, outTradeNo, totalAmount);
    }

    /**
     * 支付异步回调
     *
     * @param request
     * @return
     */
    @PostMapping("/notifyUrl")
    public String notifyUrl(HttpServletRequest request) {
        return alipayService.notifyUrl(request);
    }

    /**
     * 支付同步步回调
     *
     * @param request
     * @return
     */
    @GetMapping("/returnUrl")
    public Map<String, String[]> returnUrl(HttpServletRequest request) {
        return alipayService.returnUrl(request);
    }
}
